import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/routes/userspace/xindong_kongjian_ctr.dart';
import 'package:xindong/routes/userspace/view/xindong_kongjian_title_container.dart';
import 'package:xindong/utils/xindong_image_util.dart';

class XinDongKongJianInfoAuth extends StatelessWidget {
  const XinDongKongJianInfoAuth({super.key});

  @override
  Widget build(BuildContext context) {
    const double spacing = 8.0;
    final itemWidth = (screenWidth - 2 * 15 - 3 * spacing) / 4;
    return GetBuilder<XinDongKongJianCtr>(
        id: XinDongKongJianCtr.updateIdLoadingAuth,
        builder: (controller) {
          final list =
              controller.auths.map((e) => _buildItem(icon: e.icon, name: e.title, itemWidth: itemWidth)).toList();
          return XinDongKongJianTitleContainer(
            title: '认证信息',
            children: [
              controller.auths.isEmpty
                  ? const Text(
                      "暂无认证资料",
                      style: TextStyle(fontSize: 13, color: DZColors.placeholderColor),
                    )
                  : Wrap(spacing: spacing, runSpacing: spacing, children: list),
            ],
          );
        });
  }

  Widget _buildItem({required String icon, required String name, required double itemWidth}) {
    return SizedBox(
      width: itemWidth,
      child: Column(
        children: [
          const SizedBox(height: 8.0),
          ImageUtil.networkImageUrl(icon, width: 50, height: 50),
          const SizedBox(height: 8.0),
          Text(
            name,
            style: const TextStyle(fontSize: 13, color: DZColors.contentColor),
          )
        ],
      ),
    );
  }
}
